﻿using CDSysLDManageProject.BYDTableAdapters;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CDSysLDManageProject
{
    public partial class StageTypeSet : Form
    {
        tbl_stageinfoTableAdapter stageinfo = new tbl_stageinfoTableAdapter();
        DataTable stagedt = new DataTable();
        public StageTypeSet()
        {
            InitializeComponent();
        }

        private void StageTypeSet_Load(object sender, EventArgs e)
        {
            dgvstageset.AutoGenerateColumns = false;
            stagedt = stageinfo.GetData();
            this.Invoke(new Action(() =>
            {
                dgvstageset.DataSource = stagedt.Copy();
            }));
            


        }

        private void button1_Click(object sender, EventArgs e)
        {

            for (int i = 0; i < dgvstageset.SelectedRows.Count; i++)
            {
                int keyid = int.Parse(dgvstageset.SelectedRows[i].Cells["keyid"].Value.ToString());
                string stagetype = dgvstageset.SelectedRows[i].Cells["StageType"].Value.ToString();
                if (stagetype == "C15")
                {
                    stageinfo.UpdateSetReceipeId("C19", keyid);
                }
                else
                {
                    stageinfo.UpdateSetReceipeId("C15", keyid);
                }
            }

            dgvstageset.DataSource = stageinfo.GetData();
            //int keyid = int.Parse(dgvstageset.SelectedRows[0].Cells["keyid"].Value.ToString());
            //string stagetype = dgvstageset.SelectedRows[0].Cells["ReceipeId"].Value.ToString();
            //if (stagetype == "C15")
            //{
            //    stageinfo.UpdateSetReceipeId("C19", keyid);
            //}
            //else
            //{
            //    stageinfo.UpdateSetReceipeId("C15", keyid);
            //}
            
        }

        private void btquery_Click(object sender, EventArgs e)
        {
            dgvstageset.DataSource = stageinfo.GetData();
        }
    }
}
